#!/bin/sh

config_file="$1"
config_nvram=".nvram"

decrypt()
{
        local config_tmp=".backup.cfg.all"

        base64 -d $config_file > $config_tmp
        sed -i '1d' $config_tmp
	cp -f $config_tmp $config_nvram

        rm -f $config_tmp
}

encrypt()
{
        local config_tmp=".backup.cfg.all"
	local config_tmp_md5=".backup.cfg.md5"

	md5sum $config_nvram | cut -d ' ' -f 1 > $config_tmp_md5
	cat $config_tmp_md5 $config_nvram > $config_tmp
	base64 $config_tmp > $config_file

        rm -f $config_tmp
}

encrypt
